#include "main.h"
#include "color.h"
#include "client.h"
void client_menu()//客户界面
{
    printf(FONT_HIGHLIGHT_CYAN "\t♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥" DEFAULT_MODE "\n");
    printf(FONT_HIGHLIGHT_YELLOW "\t♥♥♥♥♥♥♥♥♥♥♥    1.查看菜单     ♥♥♥♥♥♥♥♥♥♥♥" DEFAULT_MODE "\n");
    printf(FONT_HIGHLIGHT_RED "\t♥♥♥♥♥♥♥♥♥♥♥    2.查看购物车   ♥♥♥♥♥♥♥♥♥♥♥" DEFAULT_MODE "\n");
    printf(FONT_HIGHLIGHT_BLUE "\t♥♥♥♥♥♥♥♥♥♥♥    3.查看账单     ♥♥♥♥♥♥♥♥♥♥♥" DEFAULT_MODE "\n");
    printf(FONT_HIGHLIGHT_GREEN "\t♥♥♥♥♥♥♥♥♥♥♥    0.返回上一级   ♥♥♥♥♥♥♥♥♥♥♥" DEFAULT_MODE "\n");
    printf(FONT_HIGHLIGHT_CYAN "\t♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥" DEFAULT_MODE "\n");
}
void client_choose(ManagerLinkList L)//客户菜单
{
    int input = 0;
    int sum[20] = {0};
    int num = 0;
    ManagerLinkList find_node = NULL;
    do
    {
        client_menu();
        printf(FONT_HIGHLIGHT_CYAN BLINK"请选择想要进行的操作："DEFAULT_MODE);
        scanf("%d", &input);
        system("clear");
        while (getchar() != '\n')
            ;
        switch (input)
        {
        case 1:
            Listshow_Manager(L);
            num = client_add(L, sum, num);
            break;
        case 2:
            Client_show(L, find_node, sum, num);
            break;
        case 3:
            Client_show_moeny(L, sum, num);
            break;
        case 0:
            printf(FONT_PURPLE "\t谢谢惠顾~欢迎下次光临~" DEFAULT_MODE "\n");
            sleep(2);
            break;
        default:
            printf(FONT_HIGHLIGHT_RED "\t输入错误！请重新输入：\n" DEFAULT_MODE);
            break;
        }
    } while (input);
}
ManagerLinkList LocateELem_Client(ManagerLinkList L, int e)
{
    ManagerLinkList p = L->next;
    while (p != L && (p->data.num != e))
    {
        p = p->next;
    }
    if (p != L)
        return p;
    else
        return NULL;
}
int client_add(ManagerLinkList L, int sum[], int num)//添加到购物车
{

    int input = 1;
    int i = 0;
    while (sum[i] != 0)
    {
        i++;
    }
    printf(FONT_HIGHLIGHT_CYAN"请添加想吃的菜品(序号)"DEFAULT_MODE);
    do
    {
        if (input == 1)
        {
            scanf("%d", &sum[i]);
            i++;
            num++;
        }
        else if (input == 0)
            break;
        printf(FONT_HIGHLIGHT_RED"是否继续添加菜品：是选择(1)，否选择(0)"DEFAULT_MODE);
        scanf("%d", &input);

    } while (input);
    return num;
}
void Client_show(ManagerLinkList L, ManagerLinkList find_node, int sum[], int num)//显示所有菜品
{

    for (int i = 0; i < num; i++)
    {

        int z = sum[i];
        find_node = LocateELem_Client(L, z);
        if (LocateELem_Client(L, z))
        {
            printf("\n");
            printf(FONT_HIGHLIGHT_BLUE"\t序号:%d \t菜名:%s \t介绍:%s   \t价格:%d"DEFAULT_MODE, find_node->data.num, find_node->data.name, find_node->data.introduction, find_node->data.price);
        }
        printf("\n");
        printf("\n");
    }
}
void Client_show_moeny(ManagerLinkList L, int sum[], int num)//显示总账单
{
    ManagerLinkList find_node = NULL;
    int money = 0;
    for (int i = 0; i < num; i++)
    {

        int z = sum[i];
        find_node = LocateELem_Client(L, z);
        if (LocateELem_Client(L, z))
        {
            money = money + find_node->data.price;
        }
        printf("\n");
    }
    printf(FONT_HIGHLIGHT_YELLOW"\t您一共点了%d道菜，一共%d元"DEFAULT_MODE"\n", num, money);
    printf("\n");
}